﻿using System;

namespace Flagwind.Utilities
{
	public class DeploymentCounter
	{
		#region 成员字段

		private int _failures;
		private int _successes;

		#endregion

		#region 公共属性

		public int Total
		{
			get
			{
				return _failures + _successes;
			}
		}

		public int Failures
		{
			get
			{
				return _failures;
			}
		}

		public int Successes
		{
			get
			{
				return _successes;
			}
		}

		#endregion

		#region 构造方法

		public DeploymentCounter()
		{
		}

		public DeploymentCounter(int failures, int successes)
		{
			_failures = failures;
			_successes = successes;
		}

		#endregion

		#region 内部方法

		internal int IncrementFailures(int interval = 1)
		{
			int result = 0;

			for(int i = 0; i < interval; i++)
				result = System.Threading.Interlocked.Increment(ref _failures);

			return result;
		}

		internal int IncrementSuccesses(int interval = 1)
		{
			int result = 0;

			for(int i = 0; i < interval; i++)
				result = System.Threading.Interlocked.Increment(ref _successes);

			return result;
		}

		#endregion
	}
}